package vo

import (
	"dc-news/common/global/consts"
	"dc-news/common/utils"
	"dc-news/dao/model"
	"dc-news/entity"
)

type LoginReq struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type RegisterReq struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

type ResetPasswordEmailReq struct {
	Username string `json:"username"`
	Email    string `json:"email"`
}

type ResetPasswordReq struct {
	Email    string `json:"email"`
	Token    string `json:"token"`
	Password string `json:"password"`
}

type ConfirmEmailReq struct {
	Email string `json:"email"`
	Token string `json:"token"`
}

type UpdateUserSettingReq struct {
	ThemeColor string `json:"theme_color"`
	FrontSize  int    `json:"front_size"`
	DarkMode   int    `json:"dark_mode"`
	UseMode    int    `json:"use_mode"`
}

type UpdateUserInfoReq struct {
	NickName string `json:"nick_name"`
	Avatar   string `json:"avatar"`
}

type LoginResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Id          int    `json:"id"`
		UserName    string `json:"user_name"`
		NickName    string `json:"nick_name"`
		Email       string `json:"email"`
		Avatar      string `json:"avatar"`
		AccessToken string `json:"access_token"`
	} `json:"data"`
}

type RegisterResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Id int `json:"id"`
	} `json:"data"`
}

type GetUserInfoResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Id       int    `json:"id"`
		UserName string `json:"user_name"`
		NickName string `json:"nick_name"`
		Email    string `json:"email"`
		Avatar   string `json:"avatar"`
	} `json:"data"`
}

type GetUserSettingResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		ThemeColor string `json:"theme_color"`
		FrontSize  int    `json:"front_size"`
		DarkMode   int    `json:"dark_mode"`
		UseMode    int    `json:"use_mode"`
	} `json:"data"`
}

type UploadAvatarResp struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data struct {
		Avatar string `json:"avatar"`
	} `json:"data"`
}

type GetUserChannelsResp struct {
	Code int      `json:"code"`
	Msg  string   `json:"msg"`
	Data []string `json:"data"`
}

type GetUserNewsListResp struct {
	Code       int    `json:"code"`
	Msg        string `json:"msg"`
	Pagination struct {
		Page  int `json:"page"`
		Limit int `json:"limit"`
		Total int `json:"total"`
	} `json:"pagination"`
	Data []struct {
		Id          int    `json:"id"`
		Title       string `json:"title"`
		Channel     string `json:"channel"`
		PublishTime string `json:"publish_time"`
	} `json:"data"`
}

type GetReportResp struct {
	Code int          `json:"code"`
	Msg  string       `json:"msg"`
	Data model.Report `json:"data"`
}

func NewLoginResp(user *entity.User, token string) *LoginResp {
	return &LoginResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			Id          int    `json:"id"`
			UserName    string `json:"user_name"`
			NickName    string `json:"nick_name"`
			Email       string `json:"email"`
			Avatar      string `json:"avatar"`
			AccessToken string `json:"access_token"`
		}{
			Id:          user.ID,
			UserName:    user.Username,
			NickName:    user.Nickname,
			Email:       user.Email,
			Avatar:      user.Avatar,
			AccessToken: token,
		},
	}
}

func NewRegisterResp(id int) *RegisterResp {
	return &RegisterResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			Id int `json:"id"`
		}{
			Id: id,
		},
	}
}

func NewGetUserInfoResp(user *entity.User) *GetUserInfoResp {
	return &GetUserInfoResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			Id       int    `json:"id"`
			UserName string `json:"user_name"`
			NickName string `json:"nick_name"`
			Email    string `json:"email"`
			Avatar   string `json:"avatar"`
		}{
			Id:       user.ID,
			UserName: user.Username,
			NickName: user.Nickname,
			Email:    user.Email,
			Avatar:   user.Avatar,
		},
	}
}

func NewGetUserSettingResp(setting *entity.UserSetting) *GetUserSettingResp {
	return &GetUserSettingResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			ThemeColor string `json:"theme_color"`
			FrontSize  int    `json:"front_size"`
			DarkMode   int    `json:"dark_mode"`
			UseMode    int    `json:"use_mode"`
		}{
			ThemeColor: setting.ThemeColor,
			FrontSize:  setting.FrontSize,
			DarkMode:   setting.DarkMode,
			UseMode:    setting.UseMode,
		},
	}
}

func NewUploadAvatarResp(fileName string) *UploadAvatarResp {
	return &UploadAvatarResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: struct {
			Avatar string `json:"avatar"`
		}{
			Avatar: fileName,
		},
	}
}

func NewGetUserChannelsResp(channels []string) *GetUserChannelsResp {
	return &GetUserChannelsResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: channels,
	}
}

func NewGetUserNewsListResp(news *[]model.NewsList, p *utils.Pagination) *GetUserNewsListResp {
	resp := &GetUserNewsListResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Pagination: struct {
			Page  int `json:"page"`
			Limit int `json:"limit"`
			Total int `json:"total"`
		}{
			Page:  p.Page,
			Limit: p.Size,
			Total: p.Total,
		},
		Data: nil,
	}
	for _, abstract := range *news {
		resp.Data = append(resp.Data, struct {
			Id          int    `json:"id"`
			Title       string `json:"title"`
			Channel     string `json:"channel"`
			PublishTime string `json:"publish_time"`
		}{
			Id:          abstract.ID,
			Title:       abstract.Title,
			Channel:     abstract.Channel,
			PublishTime: abstract.PublishTime,
		})
	}
	return resp
}

func NewGetReportResp(report *model.Report) *GetReportResp {
	return &GetReportResp{
		Code: consts.OKCode,
		Msg:  "ok",
		Data: *report,
	}
}
